//
//  FXTSendTaskViewController.m
//  OfferJob
//
//  Created by 郑州动力无限科技 on 2017/6/30.
//  Copyright © 2017年 郑州动力无限科技. All rights reserved.
//

#import "FXTSendTaskViewController.h"
#import "SendTableViewCell.h"
#import "UIButton+Helper.h"
#import "SendTwoTableViewCell.h"
#import "sendDetailViewController.h"
#import "renWuView.h"
#import "renwuViewController.h"
#import "CellView.h"
@interface FXTSendTaskViewController ()<UITableViewDelegate,UITableViewDataSource>

{
    NSMutableArray* _typeArray;//类型
    NSArray* _timeArray;//时间
    NSArray* _conditionArray;//条件
}
@property (nonatomic,strong)UITableView* tableview;
@property (nonatomic,strong)UITableView *tableViewchaxun;
@property (nonatomic,assign)NSInteger reminderbuttonTag;
@property (nonatomic,strong)renWuView* SheSVC;
@property (nonatomic,strong)renwuViewController* SheShiVC;
@property (nonatomic,strong)UIView *grayV;
@property (nonatomic,strong)NSArray *MArr;
@property (nonatomic,strong)NSMutableArray* listarray;
@property (nonatomic,strong)NSMutableDictionary* dic;
@property (nonatomic,strong)NSString* striD;
@end

@implementation FXTSendTaskViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUI];
    _MArr =[[NSArray alloc]init];
    _reminderbuttonTag=100;
    _listarray=[[NSMutableArray alloc]init];
    _dic=[[NSMutableDictionary alloc]init];
    _grayV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height)];
    _grayV.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.5];
    _grayV.alpha = 0;
    [self.view addSubview:_grayV];
    [self getUserInfo];
    self.striD=@"";
    
    _timeArray = @[@"按发布时间",@"按距离"];
    _conditionArray = @[@"只看男生",@"只看女生",@"查看全部",@"认证用户"];
}

// 获取
-(void)getUserInfo{
    FXTHttpRequestModel * requestModel = [[FXTHttpRequestModel alloc] init];
    requestModel.type = FXTHttpType_POST;
    requestModel.appendUrl = @"/Task/tasklist";
    NSMutableDictionary * paramDic = [NSMutableDictionary dictionary];
    [paramDic setValue:@"郑州" forKey:@"city"];
     [paramDic setValue:@"1" forKey:@"islist"];
    requestModel.paramDic = paramDic;
    requestModel.callback = ^(FXTHttpResponseModel * result, NSError *error){

        if (result.state ==FXTReponseCodeState_Success) {
            NSLog(@"2222222222%@",result.data);

            self.listarray=[result.data  objectForKey:@"list"] ;
            NSLog(@"_listdic_listdic果是%@", self.listarray);
            
            [_tableview reloadData];
            
        }else {
            [DisplayHelper displayWarningAlert:result.alertMsg];
        }
    };
    [[FXTHttpSessionManager sharedHttpSessionManager] sendHttpRequestParam:requestModel];
}

-(void)setUI
{
    
    UIView *viewTop=[[UIView alloc]initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH, 90/2.34*kAppScale)];
    viewTop.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:viewTop];
    NSArray *arrtTitle=[[NSArray alloc]initWithObjects:@"全部",@"综合排序",@"筛选", nil];
    CGFloat Width=SCREEN_WIDTH/3;
    for (int i=0; i<arrtTitle.count; i++) {
        UIButton *buttonshow=[[UIButton alloc]initWithFrame:CGRectMake(i*Width, 0, Width,  90/2.34*kAppScale)];
        buttonshow .titleLabel.font=[UIFont systemFontOfSize:13*kAppScale];
        [buttonshow setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [buttonshow setTitle:arrtTitle[i] forState:UIControlStateNormal];
        [buttonshow setTitleColor:maincolor forState:UIControlStateSelected];
        [buttonshow setImage:[UIImage imageNamed:@"icon_jian"] forState:UIControlStateNormal];
        buttonshow.tag=100+i;
        [buttonshow setImage:[UIImage imageNamed:@"arrow_2"] forState:UIControlStateSelected];
        [buttonshow TiaoZhengButtonWithOffsit:5 TextImageSite:UIButtonTextLeft];
        [buttonshow addTarget:self action:@selector(shoudata:) forControlEvents:UIControlEventTouchUpInside];
        if(i!=2)
        {
            [buttonshow addSubview:[self getView:CGRectMake(Width-.5, 20/2.34*kAppScale, .5, 50/2.34*kAppScale)]];
        }
        [viewTop addSubview:buttonshow];
    }
    UIView *viewbottom=[[UIView alloc]initWithFrame:CGRectMake(0,viewTop.bottom, self.view.width, 20/2.34*kAppScale)];
    viewbottom.backgroundColor=blackLineColore;
    [self.view addSubview:viewbottom];

    _tableview=[[UITableView alloc]initWithFrame:CGRectMake(0,110/2.34*kAppScale, SCREEN_WIDTH, SCREEN_HEIGHT-64-49-110/2.34*kAppScale)];
    _tableview.delegate=self;
    _tableview.dataSource=self;
    _tableview.backgroundColor=backgroundcolor;
    [_tableview setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [_tableview registerClass:[SendTableViewCell class] forCellReuseIdentifier:@"SendTableViewCell"];
    [self.view addSubview:_tableview];
    
    
    _tableViewchaxun=[[UITableView alloc]initWithFrame:CGRectMake(0,viewTop.bottom+.5, self.view.width, self.view.height-viewbottom.bottom) style:UITableViewStyleGrouped];
    _tableViewchaxun.hidden=YES;
    _tableViewchaxun.backgroundColor=[[UIColor blackColor]colorWithAlphaComponent:0.3];
    [self.view addSubview:_tableViewchaxun];
    
  

    [_tableViewchaxun reloadData];
    
}

-(FXTNavType)getNavType {
    return   FXTNavTypeOnlyTitle;
}
- (void)ShouShiTuianPian:(UITapGestureRecognizer *)ShouShi{
    NSLog(@"我的手势绑定的订单是%ld",  ShouShi.view.tag);
    _tableViewchaxun.hidden=YES;
    if (ShouShi.view.tag==11) {
        
        
    }
}
-(void)sure
{
    _tableViewchaxun.hidden=YES;
   [self getData];
}
-(void)getData
{
    UIButton* btn=(UIButton* )[self.view viewWithTag:100];
    if (btn.tag==100) {
         NSArray*MArr=@[@"智能排序",@"价格从高到低",@"价格从低到高",@"时间优先"];
        float setY=10*kAppScale;
        
        for (int i=0; i<[_MArr count]; i++) {
            CellView *cell=[[CellView alloc]initWithFrame:CGRectMake(0, setY, self.view.width, 44*kAppScale)];
            cell.titleLabel.textColor=blackTextColor;
            cell.tag=10+i;
            cell.titleLabel.font=[UIFont  systemFontOfSize:13*kAppScale];
            cell.titleLabel.text=[MArr objectAtIndex:i];
            cell.titleLabel.textAlignment=NSTextAlignmentLeft;
            [_tableViewchaxun addSubview:cell];
            
            
            UITapGestureRecognizer* singleRecognizer;
            singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ShouShiTuianPian:)];
            singleRecognizer.numberOfTapsRequired = 1;
            
            [cell addGestureRecognizer:singleRecognizer];
            setY=cell.bottom;
        }
    }else{
   NSArray* MArr=@[@"按区域筛选",@"按时间筛选"];
        float setY=10*kAppScale;
        
        for (int i=0; i<[_MArr count]; i++) {
            CellView *cell=[[CellView alloc]initWithFrame:CGRectMake(0, setY, self.view.width, 44*kAppScale)];
            cell.titleLabel.textColor=blackTextColor;
            cell.tag=10+i;
            cell.titleLabel.font=[UIFont  systemFontOfSize:13*kAppScale];
            cell.titleLabel.text=[MArr objectAtIndex:i];
            cell.titleLabel.textAlignment=NSTextAlignmentLeft;
            [_tableViewchaxun addSubview:cell];
            
            
            UITapGestureRecognizer* singleRecognizer;
            singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ShouShiTuianPian:)];
            singleRecognizer.numberOfTapsRequired = 1;
            
            [cell addGestureRecognizer:singleRecognizer];
            setY=cell.bottom;
        }
    }
    [_tableViewchaxun  reloadData];


}
#pragma mark---EVENT---
-(void)shoudata:(UIButton *)button
{

    NSLog(@"eeeeeeee%ld",(long)button.tag);
    
    if(button.tag==_reminderbuttonTag)
    {

        _tableViewchaxun.hidden=NO;
        // button.selected=!button.selected;
        button.selected=YES;
        _reminderbuttonTag=button.tag;
        [_tableViewchaxun reloadData];
  
        return;
    }
    _tableViewchaxun.hidden=NO;
    UIButton *buttonbefore=(UIButton *)[self.view viewWithTag:_reminderbuttonTag];
    buttonbefore.selected=NO;
    button.selected=YES;
    _reminderbuttonTag=button.tag;
    [self getData];
    [_tableViewchaxun reloadData];
    

}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _listarray .count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.listarray.count>0) {
        _dic=self.listarray[indexPath.row];
        NSLog(@"_dic_dic_dic%@",_dic);
    }
    
    SendTableViewCell *cell = (SendTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"SendTableViewCell" forIndexPath:indexPath];
    cell.selectionStyle=0;
    cell.imageView.backgroundColor=[UIColor redColor];
    cell.nameLB.text=[NSString stringWithFormat:@"%@",_dic[@"nickname"]];
    CGSize lblSize = [cell.nameLB.text boundingRectWithSize:CGSizeMake(MAXFLOAT, 30*kAppScale) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} context:nil].size;
    cell.nameLB.frame = CGRectMake(80*kAppScale, 30*kAppScale, lblSize.width, lblSize.height);
    cell.iconImage.frame=CGRectMake( cell.nameLB.right+5*kAppScale, 30*kAppScale,15*kAppScale,15*kAppScale);
    cell.iconImage.image=[UIImage imageNamed:@"icon_bao"];
    
    [cell .imagView setImageWithURL:[NSURL URLWithString:    [NSString stringWithFormat:@"%@",_dic[@"header_pic"]]] placeholderImage:[UIImage imageNamed:@""]];
    cell.titleLB.text=[NSString stringWithFormat:@"%@",_dic[@"title"]];
    cell.numLB.text= [NSString stringWithFormat:@"人数：%@人",_dic[@"num"]];
    if ([_dic[@"jiesuan_type"]isEqualToString:@"1"]) {
        cell.dayLB.text=@"日结";
    }else if ([_dic[@"jiesuan_type"]isEqualToString:@"2"]){
        cell.dayLB.text=@"小时结";
    }else if ([_dic[@"jiesuan_type"]isEqualToString:@"3"]){
        cell.dayLB.text=@"次结";
    }else if ([_dic[@"jiesuan_type"]isEqualToString:@"4"]){
        cell.dayLB.text=@"完工结";
    }
    NSString* dayname;
    if ([[_dic objectForKey:@"jiesuan_unit"]isEqualToString:@"1"]) {
        dayname=@"天";
    }else if ([[_dic objectForKey:@"jiesuan_unit"]isEqualToString:@"2"]) {
        dayname=@"小时";
    }else  if ([[_dic objectForKey:@"jiesuan_unit"]isEqualToString:@"3"]){
        dayname=@"次";
    }else{
        dayname=@"预算";
    }
    
    
    
    
    cell. moneyLB.attributedText=[[NSString stringWithFormat:@"<red14>%@元</red14><heise12>/%@</heise12>",_dic[@"jiesuan_price"],dayname]attributedStringWithStyleBook:[self Style]];
    cell.timeLB.text=[NSString stringWithFormat:@"%@-%@", [NSString stringWithFormat:@"%@",_dic[@"date_starttime"]], [NSString stringWithFormat:@"%@",_dic[@"date_endtime"]]];

    return cell;
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80*kAppScale;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    sendDetailViewController*sendDetailVC=[[sendDetailViewController alloc]init];
    sendDetailVC.strID=self.listarray[indexPath.row][@"task_id"];
       NSLog(@"sendDetailVC.strID=单是%@", sendDetailVC.strID);
    [self.navigationController pushViewController:sendDetailVC animated:YES];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
